package m.base.util;

import m.appserver.ActionRedirect;
import m.base.model.LevelInfo;
import m.common.action.VuePageResult;
import m.common.action.VueResult;
import m.system.exception.MException;
import m.system.util.DateUtil;
import m.system.util.ObjectUtil;

public class LevelUtil {
    public static ActionRedirect toErrorPage(String msg,boolean hasBack) throws Exception {
        return new ActionRedirect(
            new VuePageResult("page/errorForLevel.js")
                .addParam("error","级别限制")
                .addParam("errorMessage",msg)
                .addParam("level",getLevel().getOid())
                .addParam("endDate", DateUtil.format(PowerUtil.getSessionStore(true).getLevelEndDate(),"yyyy-MM-dd"))
        );
    }
    public static LevelInfo getLevel() throws Exception {
        return PowerUtil.getSessionStore(true).getLevel();
    }

    /**
     * 导出功能
     */
    public static boolean exportFunc() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return false;
        return LevelInfo.Yes.equals(getLevel().getExportFunc());
    }

    /**
     * 图表功能
     */
    public static boolean chartFunc() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return false;
        return LevelInfo.Yes.equals(getLevel().getChartFunc());
    }
    /**
     * 报价单
     */
    public static boolean offerFunc() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return false;
        return LevelInfo.Yes.equals(getLevel().getOfferFunc());
    }
    /**
     * 统计汇总
     */
    public static boolean collectFunc() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return false;
        return LevelInfo.Yes.equals(getLevel().getCollectFunc());
    }

    /**
     * 用户数量
     */
    public static int userNum() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return 1;
        return getLevel().getUserNum();
    }
    /**
     * 仓库数量
     */
    public static int repositoryNum() throws Exception {
        if(ObjectUtil.isEmptyOid(getLevel())) return 1;
        return getLevel().getRepositoryNum();
    }
}
